package net.core.base.ibatis;

import java.util.List;
import java.util.Map;

import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

public class BaseSqlMapDAO extends SqlMapClientDaoSupport {
	protected DataSourceTransactionManager transactionManager;
	protected DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
	protected TransactionStatus status;
	private SqlMapClientTemplate smcTemplate = getSqlMapClientTemplate();

	@SuppressWarnings("unchecked")
	public List queryForList(String statementName, Object parameterObject) {
		return this.smcTemplate.queryForList(statementName, parameterObject);
	}

	@SuppressWarnings("unchecked")
	public List queryForList(String statementName, Object parameterObject, int skipResults, int maxResults) {
		return this.smcTemplate.queryForList(statementName, parameterObject, skipResults, maxResults);
	}

	@SuppressWarnings("unchecked")
	public Map queryForMap(String statementName, Object parameterObject, String keyProperty) {
		return this.smcTemplate.queryForMap(statementName, parameterObject, keyProperty);
	}

	@SuppressWarnings("unchecked")
	public Map queryForMap(String statementName, Object parameterObject, String keyProperty, String valueProperty) {
		return this.smcTemplate.queryForMap(statementName, parameterObject, keyProperty, valueProperty);
	}

	public Object queryForObject(String statementName, Object parameterObject) {
		return this.smcTemplate.queryForObject(statementName, parameterObject);
	}

	public Object queryForObject(String statementName, Object parameterObject, Object resultObject) {
		return this.smcTemplate.queryForObject(statementName, parameterObject, resultObject);
	}

	public int update(String statementName, Object parameterObject) {
		return this.smcTemplate.update(statementName, parameterObject);
	}

	public void update(String statementName, Object parameterObject, int requiredRowsAffected) {
		this.smcTemplate.update(statementName, parameterObject, requiredRowsAffected);
	}

	public Object insert(String statementName, Object parameterObject) {
		return this.smcTemplate.insert(statementName, parameterObject);
	}

	public void delete(String statementName, Object parameterObject) {
		this.smcTemplate.delete(statementName, parameterObject);
	}

	public String sequences(String seqName) {
		return (String) this.smcTemplate.queryForObject("getSequencesValue", seqName);
	}

	public DataSourceTransactionManager getTransactionManager() {
		return this.transactionManager;
	}

	public void setTransactionManager(DataSourceTransactionManager transactionManager) {
		this.transactionManager = transactionManager;
	}

	public SqlMapClientTemplate getSmcTemplate() {
		return this.smcTemplate;
	}

	public void setSmcTemplate(SqlMapClientTemplate smcTemplate) {
		this.smcTemplate = smcTemplate;
	}
}